package org.redrider.shop.domain
class WorkOrder {
    Customer customer
    Vehicle vehicle
    UserData createdBy
    UserData tech
    OrderStatus status
    String workRequested
    Date dateCreated
    Date lastUpdate
    BigInteger mileage
    Float totalCost

    static transients = ['totalCost','customer','vehicle']
    static hasMany = [workSplits:WorkOrderSplits]
    static belongsTo = [hMapper:HistoryMapper]

    static constraints = {
        customer()
        vehicle()
        mileage()
        workRequested(size:0..20000)
        createdBy(nullable:false)
        dateCreated (nullable: true)
        tech(nullable:true)
        status()
        lastUpdate(nullable: true)
        status(nullable: false)
    }

    Float getTotalCost(){
        Float tot
        workSplits.each {
            tot += it.cost
        }
    }

    Customer getCustomer(){
        hMapper.history.customer
    }

    Vehicle getVehicle(){
        hMapper.history.vehicle
    }
}
